//
//  YRBaseViewController.swift
//  YR 微博
//
//  Created by cyr on 15/10/8.
//  Copyright © 2015年 cyr. All rights reserved.
//

import UIKit

class YRBaseViewController: UITableViewController,YRVisitorLoginViewDelegate {

    // 记录用户的登陆状态
   var userLogon = YRUserAccount.sharedAccount != nil

    
    // 设置访客视图的属性
   var visitorView: YRVisitorLoginView?
    
    override func loadView() {
        
        //根据用户是否登陆判断出现什么界面
        userLogon ? super.loadView() : setupVisitorView()
        
        
    }
    
    // 设置访客视图
    
    private func setupVisitorView(){
        
        visitorView = YRVisitorLoginView()
        
        view = visitorView
        
        visitorView?.delegate = self
        
        // 设置状态栏
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "yrVisitorLoginViewWillRegister")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "yrVisitorLoginViewWillRegister")
        
    }
    
    
    // MARK: -YRVisitorLoginViewDelegate
    
    func yrVisitorLoginViewWillRegister() {
        print("注册")
    }
    
    func yrVisitorLoginViewWillLogin() {
        
        let nav = UINavigationController(rootViewController: YROAuthViewController())
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    
}
